<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of insert
 *
 * @author Luis Alberto
 */
session_start();

// Liberias de Twitter.
include 'EpiCurl.php';
include 'EpiOAuth.php';
include 'EpiTwitter.php';
include 'secret.php';

// Librerias de Twitter

include("libs/adodb/adodb.inc.php");
include("configuracion.php");
include("include/GSession.php");
$usrcod = $_SESSION['usr_cod'];
$gsession = new GSession();
if (!$gsession->inicio_session())
     header("location:./index.php");
if(isset($_POST['content']))
{
    $men = $_POST['content'];
    $content= utf8_decode($men);
    $db = ADONewConnection(DRIVER);
    $db->Connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
    $cns = "insert into mensaje (contenido, usr_cod) values ('$content',$usrcod)";
    $rs = $db->Execute($cns);
    if($rs)
    {

        // Publicacion en Twitter.
        $consocial = $gsession->getConfSocial(1);
        $oauth_token = $consocial['cs_idtoken'];
        $oauth_token_secret =  $consocial['cs_idtoken_secret'];

        if(strlen($oauth_token)>0 || strlen($oauth_token_secret)>0 )
        {
            $Twitter = new EpiTwitter($consumer_key, $consumer_secret);
            $Twitter->setToken($oauth_token,$oauth_token_secret);
            //$message Status update
            $status = $Twitter->post_statusesUpdate(array('status' =>"$men"."@uibasoft"));
            $status->response;
        }
       
        // Publicacion en Twitter.

        $cns = "select * from mensaje where usr_cod = '$usrcod' order by codigo desc";
        $rs = $db->Execute($cns);
        if($rs)
        {
            $dato = $rs->fetchRow();
            $msg = utf8_encode(($dato['contenido']));
            $msg_id = $dato['codigo'];
        }
    }   
}
?>
<li class="record">
    <a href="http://www.twitter.com/uibasoft"><img src="img/emsic.png" alt="EMSIC" class="egg_Pic"></a>
    <div align="left" class="egg_Body">
    <div class="UIStory_Hide"><a href="#" class="delbutton" id="<?php echo $msg_id; ?>"><img src="img/del.png" alt="Eliminar Mensaje <?php echo $msg_id; ?>" title="Eliminar Mensaje <?php echo $msg_id; ?> " style="color:#FFFFFF"></a></div>
    <h3 class="egg_Message"><a href="http://www.twitter.com/uibasoft" class="egg_Name">EMSIC</a><br><?php echo $msg; ?></h3>
    </div>
</li>